package com.ruoyi.bom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bom.domain.ErpProductBom;
import com.ruoyi.bom.service.IErpProductBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品BOMController
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/bom/product_bom")
public class ErpProductBomController extends BaseController
{
    @Autowired
    private IErpProductBomService erpProductBomService;

    /**
     * 查询产品BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpProductBom erpProductBom)
    {
        startPage();
        List<ErpProductBom> list = erpProductBomService.selectErpProductBomList(erpProductBom);
        return getDataTable(list);
    }

    /**
     * 导出产品BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:export')")
    @Log(title = "产品BOM", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpProductBom erpProductBom)
    {
        List<ErpProductBom> list = erpProductBomService.selectErpProductBomList(erpProductBom);
        ExcelUtil<ErpProductBom> util = new ExcelUtil<ErpProductBom>(ErpProductBom.class);
        util.exportExcel(response, list, "产品BOM数据");
    }

    /**
     * 获取产品BOM详细信息
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(erpProductBomService.selectErpProductBomByProductId(productId));
    }

    /**
     * 新增产品BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:add')")
    @Log(title = "产品BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpProductBom erpProductBom)
    {
        return toAjax(erpProductBomService.insertErpProductBom(erpProductBom));
    }

    /**
     * 修改产品BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:edit')")
    @Log(title = "产品BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpProductBom erpProductBom)
    {
        return toAjax(erpProductBomService.updateErpProductBom(erpProductBom));
    }

    /**
     * 删除产品BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:product_bom:remove')")
    @Log(title = "产品BOM", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(erpProductBomService.deleteErpProductBomByProductIds(productIds));
    }
}
